﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LDSP.BRL;
using ImplementationInitialization;
using ImplementationInitialization.Constants;

namespace DataInitial.Util
{
    public class CodificationNameCorrect
    {
        public void Run()
        {
            IDictionary<string, Codification> codifications = BaseDataInitial.GetExistedCodification();

            foreach (string key in codifications.Keys)
            {
                Codification cod = codifications[key];
                if (!string.IsNullOrEmpty(cod.Name) && (cod.Name.Contains(SpecialMark.SPLITTER_ENTER) || cod.Name.Contains(SpecialMark.SPLITTER_BLANK)))
                {
                    cod.Name = CorrectName(cod.Name);
                    cod.Update();
                }
            }
        }

        private string CorrectName(string p)
        {
            string result = p;
            string splitter = SpecialMark.SPLITTER_ENTER;
            if (p.Contains(SpecialMark.SPLITTER_BLANK))
            {
                splitter = SpecialMark.SPLITTER_BLANK;
            }

            return p.Substring(0, p.IndexOf(splitter));
            ;
        }
    }
}
